class OrderExaminationsController < ApplicationController
  # GET /order_examinations
  # GET /order_examinations.xml
  def index
    @order_examinations = OrderExamination.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @order_examinations }
    end
  end

  # GET /order_examinations/1
  # GET /order_examinations/1.xml
  def show
    @order_examination = OrderExamination.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @order_examination }
    end
  end


 def add_resoult
    order_examination = OrderExamination.find(params[:id])
    @exam_resoult = TempExaminationResoult.create(:order_examination_id => order_examination.id)

    examination_type = order_examination.examination_type
    for p_norm in examination_type.param_norms
      @exam_resoult.param_resoults.build(:param_norm_id => p_norm.id)
#         @exam_resoult.param_resoults.build
#        param_resoult.param_norm_id = p_norm.id
#           ParamResoult.create(:temp_examination_resoult_id => @exam_resoult.id, :param_norm_id => p_norm.id)
    end
 end

  # GET /order_examinations/new
  # GET /order_examinations/new.xml
  def new
    @order_examination = OrderExamination.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @order_examination }
    end
  end

  # GET /order_examinations/1/edit
  def edit
    @order_examination = OrderExamination.find(params[:id])
  end

  # POST /order_examinations
  # POST /order_examinations.xml
  def create
    @order_examination = OrderExamination.new(params[:order_examination])

    respond_to do |format|
      if @order_examination.save
        flash[:notice] = 'OrderExamination was successfully created.'
        format.html { redirect_to(@order_examination) }
        format.xml  { render :xml => @order_examination, :status => :created, :location => @order_examination }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @order_examination.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /order_examinations/1
  # PUT /order_examinations/1.xml
  def update
    @order_examination = OrderExamination.find(params[:id])

    respond_to do |format|
      if @order_examination.update_attributes(params[:order_examination])
        flash[:notice] = 'OrderExamination was successfully updated.'
        format.html { redirect_to(@order_examination) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @order_examination.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /order_examinations/1
  # DELETE /order_examinations/1.xml
  def destroy
    @order_examination = OrderExamination.find(params[:id])
    @order_examination.destroy

    respond_to do |format|
      format.html { redirect_to(order_examinations_url) }
      format.xml  { head :ok }
    end
  end
end
